<!DOCTYPE html>
<html lang="en">
<head th:include="cultivateWeb/header :: culHeaderCss"></head>
</head>
<!--<link href="/css/web/themes/about.css" rel="stylesheet">-->
<link rel="stylesheet" href="/css/certificateWeb/workNews/workNews.css">
<body id="body"  style=" height: 100%;width: 100%; position: absolute;">
<header th:include="cultivateWeb/header :: header(true)"></header>
<main id="main" style="min-height: calc(100% - 393px)">
    <input type="hidden" id="myname" th:value="${name}"/>
    <section class="main-md " style="margin: 30px auto;">
        <!--        <div class="div_1">-->
        <!--            <ul>-->
        <!--                <li class="this"><a href="/certificate/policyInfo">政策信息</a></li>-->
        <!--&lt;!&ndash;                <li><a href="/certificate/noticeInfo">通知公告</a></li>&ndash;&gt;-->
        <!--&lt;!&ndash;                <li><a href="/certificate/tradeInfo">工作动态</a></li>&ndash;&gt;-->
        <!--&lt;!&ndash;                <li><a href="/certificate/schoolMien">试点院校风采</a></li>&ndash;&gt;-->
        <!--            </ul>-->
        <!--        </div>-->
        <!--        <div class="div_2">-->
        <div id="news" style="min-height: 380px;font-size: 16px;width: 100% "></div>
        <div id="page" style="margin-top: 20px;display: flex;  justify-content: center;  align-items: center;"></div>
        <!--        </div>-->

        <div style="clear: both"></div>
    </section>
</main>
<!--<div th:include="certificateWeb/headFoot :: footer"></div>-->
<div class="footer" th:include="cultivateWeb/header :: footer"></div>
<script>
    //设置分页数据
    const mylist = {
        sums: 100,
        limit: 12,
        page: 1,
        number: 1,
    }
    //页面数据
    const mypageData={}
    const getData = () => {
        $.ajax({
            url: "/jzApi/index/selNewsList",
            type: 'GET',
            data: {
                firstColumn: '证书考试门户',
                columnName: '政策信息',
                current: mylist.page,
                number: mylist.limit,
            },
            success: function (res) {
                if (res.code == '0') {
                    mylist.sums = res.data.total
                }

                if (res.data.pages == 0) {
                    $("#news").html('<div style="color: #000;font-size: 16px; text-align: center;  line-height: 300px;">未查询到信息 请更换关键词后重试</div>');
                } else {
                    var list = res.data.records;
                    var news = '';
                    list.forEach(function (item, index) {
                        var a = '';
                        if (item.istop == 1) {
                            a = '<span class="top">🔝置顶</span>';
                        }
                        let title=a + item.title
                        //缩小

                        const dom = document.createElement('span');
                        dom.style.display = 'inline-block';
                        dom.style.fontSize='16px';
                        dom.textContent = title;
                        document.body.appendChild(dom);

                            let num=title.length
                           while (dom.clientWidth>($('#news')[0].clientWidth - 300)){
                               num=num-6
                               title=title.substring(0,num)+'...'
                               dom.textContent = title;
                           }


                        document.body.removeChild(dom);
                        news += '<a href="/certificate/policyDetail?id=' + item.id + '" target="_blank" class="flex"><span class="span_2">' +title + '</span>' +
                            '<span class="span_1">' + item.createrDate + '</span></a>';
                    });
                    $("#news").html(news);
                    // page(1,res.data.pages);
                }
                layui.use(['laypage'], function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'page',
                        count: mylist.sums,
                        limit: mylist.limit,
                        limits: [12, 50, 100, 150],
                        curr: mylist.page,
                        layout: ['count', 'prev', 'limit', 'page', 'next', 'refresh', 'skip'],
                        jump: function (obj) {
                            //调接口
                            mylist.page = obj.curr
                            mylist.limit = obj.limit
                            if (mylist.number > 1) {
                                mylist.number = 1
                                getData()
                            } else {
                                mylist.number = 2;
                            }


                        }
                    });
                })

            }
        });
    }
    var myData1=[]
    const getData1=()=>{
        myData1=[]
        //等待提示
        $("#news").html('<div style="color: #000;font-size: 16px; text-align: center;  line-height: 300px;">正在查询信息 请稍等</div>');
        $.ajax({
            url: "/jzApi/index/indexSearch",
            type: 'GET',
            data: {
                queryParam:$("#myname").val(),
                current:mylist.page,
                size:mylist.limit
            },
            success: function (res) {

                if (res.code == '0') {
                    mylist.sums = res.data.total
                }else{
                    $("#news").html('<div style="color: #000;font-size: 16px; text-align: center;  line-height: 300px;">后台财务 请稍后再试</div>');
                }

                if (res.data.total == 0 ||res.data.total == '0') {
                    $("#news").html('<div style="color: #000;font-size: 16px; text-align: center;  line-height: 300px;">未查询到信息 请更换关键词后重试</div>');
                } else {
                    myData1= res.data.records;

                    //需要进行前端分页
                    // mylist.page
                    // mylist.limit
                    var list =myData1.slice((mylist.page - 1),(mylist.page * mylist.limit))
                    var listItem = '';
                    list.forEach(function (item, index) {
                        var a = '';
                        if (item.istop == 1) {
                            a = '<span class="top">🔝置顶</span>';
                        }
                        if(item.newType=='3'||item.newType==3){
                            listItem += `<a href="/certificate/policyDetail?id=${item.id}" target="_blank" class="flex">
                                     <div class="span_2" style="    display: flex; flex-direction: column;">
                                         <span>${a} ${item.name}</span>
                                         <span> ${item.couIntroduce}</span>
                                     </div>
                                     <div class="span_1"> ${item.createrDate}</div>
                                     </a>`;
                        }else {
                            listItem += `<a href="/couInfo/couInfo?id=${item.id}&pageSign=${item.newType}" target="_blank" class="flex">
                                      <div class="span_2" style="    display: flex; flex-direction: column;">
                                                <span>${a} ${item.name} </span>
                                                <span> ${item.couIntroduce}</span>
                                       </div>
                                      <div class="span_1">${item.createrDate}</div>
                                      </a>
                                `;
                        }

                    });
                    $("#news").html(listItem);
                    // page(1,res.data.pages);
                }
                layui.use(['laypage'], function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'page',
                        count: mylist.sums,
                        limit: mylist.limit,
                        limits: [20, 50, 100, 150],
                        curr: mylist.page,
                        layout: ['count', 'prev', 'limit', 'page', 'next', 'refresh', 'skip'],
                        jump: function (obj) {
                            mylist.page = obj.curr
                            mylist.limit = obj.limit
                            if(myData1.length==0){
                                $("#news").html('<div style="color: #000;font-size: 16px; text-align: center;  line-height: 300px;">未查询到信息 请更换关键词后重试</div>');
                            }else{

                                var news = '';
                                var list =myData1.slice((mylist.page - 1)*mylist.limit,mylist.page*mylist.limit)
                                list.forEach(function (item, index) {
                                    var a = '';
                                    if (item.istop == 1) {
                                        a = '<span class="top">🔝置顶</span>';
                                    }
                                    if(item.newType=='3'||item.newType==3){
                                        news += `<a href="/certificate/policyDetail?id=${item.id}" target="_blank" class="flex">
                                     <div class="span_2" style="    display: flex; flex-direction: column;">
                                         <span>${a} ${item.name}</span>
                                         <span> ${item.couIntroduce}</span>
                                     </div>
                                     <div class="span_1"> ${item.createrDate}</div>
                                     </a>`;
                                    }else {
                                        news += `<a href="/couInfo/couInfo?id=${item.id}&pageSign=${item.newType}" target="_blank" class="flex">
                                      <div class="span_2" style="    display: flex; flex-direction: column;">
                                                <span>${a} ${item.name} </span>
                                                <span> ${item.couIntroduce}</span>
                                       </div>
                                      <div class="span_1">${item.createrDate}</div>
                                      </a>
                                `;
                                    }

                                });
                                $("#news").html(news);
                            }



                        }
                    });
                })

            }
        });
    }
    $(function () {
        if($("#myname").val()){
            getData1();
        }else{
            getData()
        }

    });

</script>
<script type="text/javascript" src="/js/xlPaging.js"></script>
</body>
</html>